﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleExpression
{
    public class LinkEntityExpression : Expression
    {
        private JoinOperator joinOperator;
        private PropertyMetadata fieldFrom;
        private PropertyMetadata fieldTo;
        private FilterExpression filterExpression;

		/*private EntityMetadata entityFrom;
		private EntityMetadata entityTo;*/

        //XML Required
        public LinkEntityExpression()
        { 
        
        }

        public LinkEntityExpression(JoinOperator joinOperator, PropertyMetadata fieldFrom, PropertyMetadata fieldTo)
        {
            this.joinOperator = joinOperator;
            this.fieldFrom = fieldFrom;
            this.fieldTo = fieldTo;
            this.filterExpression = new FilterExpression(fieldFrom.EntityMetadata);
            this.FilterExpression.Add(fieldFrom, ConditionOperator.Equals, fieldTo);
        }

		public LinkEntityExpression(JoinOperator joinOperator, EntityMetadata entityFrom, EntityMetadata entityTo)
		{
			this.joinOperator = joinOperator;
			this.fieldTo = new PropertyMetadata(entityTo);
			this.fieldFrom = new PropertyMetadata(entityFrom);

		}

        public EntityMetadata EntityFrom
        {
            get { return this.fieldFrom.EntityMetadata; }
        }

        public EntityMetadata EntityTo
        {
            get { return this.fieldTo.EntityMetadata; }
        }

        public JoinOperator JoinOperator
        {
            get { return this.joinOperator; }
            set { this.joinOperator = value; }
        }

        public PropertyMetadata FieldFrom
        {
            get { return this.fieldFrom; }
            set { this.fieldFrom = value; }
        }

        public PropertyMetadata FieldTo
        {
            get { return this.fieldTo; }
            set { this.fieldTo = value; }
        }

        public FilterExpression FilterExpression
        {
            get { return this.filterExpression; }
            set { this.filterExpression = value; }
        }

        #region Expression

        public override void Accept(ExpressionVisitor visitor)
        {
            visitor.Visit(this);
        }

        #endregion
    }
}
